﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SetQuality.aspx.cs" Inherits="Credit_Teacher_RuleSettings_SetQuality" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>学分级别设置</title>
    <link href="../../../Common/css/main.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="../../../Common/Js/jquery.js"></script>

    <script type="text/javascript" src="../../../Common/Js/common.js"></script>

    <script type="text/javascript" src="../../../Common/Js/msg.js"></script>
    <script type="text/javascript">
    var doThis=null;
    function SetDoWhat(fun)
    {
        doThis = fun;
    }
    
    function onSchange()
    {
        var subjectSelect = document.getElementById('subjectSelect');
        var value = subjectSelect.options[subjectSelect.selectedIndex].value;
        var typeid = document.getElementById('typeid');
        var btnBind = document.getElementById('btnBind');
        if(typeid!=null && btnBind!=null)
        {
            typeid.value = value;
            btnBind.click();
        }
        settingChange = false;
        SetDoWhat(null);
    }

    function OnclosePage(obj)
    {
        showConfirmBox("提示", "是否要保存设置?", SaveSettings, null,obj);
    }


    var settingChange = false;
    //选项变更
    function onSubjectSelect(index)
    {
        if(index>=0)
        {
            if(settingChange==true)
            {
                SetDoWhat(onSchange);
                showConfirmBox("提示", "是否要保存设置?", SaveSettings, null,onSchange);
            }
            else
            {
                onSchange();
            }
        }
    }
    //增加一条设置
    function AddSetting()
    {   
        if(document.getElementById('settingTable') != null)
        {
            document.getElementById('btnAddKind').disabled= true ;
            document.getElementById('btnSaveKind').disabled= true ;
            var table = document.getElementById('settingTable');     
            var newTr = table.insertRow();

            var newcell = newTr.insertCell();
            newcell.style.textAlign = "left";
            newcell.style.paddingLeft = "5px";
            newcell.innerHTML = "<input id='newClassName' maxLength=19 style='text-align:left;border:solid #a5a5a5 1px;width:120px;'  onpaste='return false;' ondragenter='return false' value='<请输入名称>'  onblur=\"AddOne(this)\" \>";

            newcell = newTr.insertCell();
            newcell.style.textAlign = "right";
            newcell.style.paddingRight = "5px";
//            newcell.disabled= true ;
//            newcell.innerHTML = "<SELECT id='Select1'><OPTION  selected >>=</OPTION><OPTION  >></OPTION><OPTION ><</OPTION><OPTION  ><=</OPTION></SELECT>";
            
            newcell = newTr.insertCell();
            newcell.style.textAlign = "right";
            newcell.style.paddingRight = "5px";
//            newcell.innerText = "100";
            
            newcell = newTr.insertCell();
            newcell.style.textAlign = "center";
//            newcell.innerHTML = "<img src='../../../Common/images/delete_icon.gif' alt='删除此项' class='imageBtnStyle' onclick='DelClass(this.parentElement.parentElement);' />";
            document.getElementById('newClassName').select();

        }
        else
        {
//            showMassgeBox("提示","请您先选择要添加的年级",1,null);
            return -1;
        }
        return 1;
    }
    
    function AddOne(obj)
    {
        var settingName = obj.value.Trim();
        var rowIndex = obj.parentElement.parentElement.rowIndex;

        var settingTable = document.getElementById('settingTable');
        settingTable.rows(rowIndex).cells(0).innerHTML = "<input  maxlength='19' class='txtStyle' style='text-align: left; border-left: 0px; width:120px;border-top: 0px; border-right: 0px; border-bottom: 0px;' id='n"+settingName+
                                            "' value='"+settingName+"' oldvalue='"+settingName+"' onfocusout='optionSettingName(this)' onclick='modi(this)' onkeypress='return event.keyCode>128' onpaste='return false;' ondragenter='return false' readonly>";
        settingTable.rows(rowIndex).cells(1).innerHTML = "<input onkeypress='return event.keyCode>=48&&event.keyCode<=57' onpaste='return false;'   ondragenter='return false' maxlength='4' class='txtStyle' style='text-align: right;  border-left: 0px; width: 80px; border-top: 0px; border-right: 0px; border-bottom: 0px;' id='Text1' value='80' oldvalue='80'  onfocusout='optionSettingScoremin(this)' onclick='modi(this)' readonly />";
        settingTable.rows(rowIndex).cells(2).innerHTML = "<input onkeypress='return event.keyCode>=48&&event.keyCode<=57' onpaste='return false;'   ondragenter='return false' maxlength='4' class='txtStyle' style='text-align: right;  border-left: 0px; width: 80px; border-top: 0px; border-right: 0px; border-bottom: 0px;' id='Text2' value='100' oldvalue='100' onfocusout='optionSettingScoremax(this)' onclick='modi(this)' readonly />";
        settingTable.rows(rowIndex).cells(3).innerHTML = "<img style='cursor:hand' src='../../../Common/images/delete_icon.gif' alt='删除此项' class='imageBtnStyle' onclick='DelSetting(this.parentElement.parentElement);' />";
        if(settingName == null || settingName.length == 0 || settingName == '<请输入名称>' )
        {        
            settingTable.deleteRow(rowIndex);
        }
        else
        {
            settingTable.rows(rowIndex).id = "null";
            settingTable.rows(rowIndex).objname = settingName;
            settingTable.rows(rowIndex).objmax = 100;
            settingTable.rows(rowIndex).objmin = 80;
            settingChange = true;
        }
        document.getElementById('btnAddKind').disabled= false ;
        document.getElementById('btnSaveKind').disabled= false ;

    }
    //焦点移开后判断更新
    function optionSettingName(obj)
    {
        s=true;
        var id = obj.parentElement.parentElement.id;
        var value = obj.value;
        if(obj.getAttribute("oldvalue") != null && (value.length == 0 || value == obj.getAttribute("oldvalue")) )
        {   
            obj.setAttribute("value",obj.getAttribute("oldvalue")); 
        }
        else
        {
            obj.setAttribute("oldvalue",value); 
            settingChange = true;
        }
        unModi(obj,'left');
         obj.parentElement.parentElement.objname = obj.value;
    }
    //焦点移开后判断更新
    function optionSettingScore(obj)
    {
        s=true;
        var id = obj.parentElement.parentElement.id;
        var value = obj.value;

        if(value.length == 0 ||  ( /\D/.test(value)))
        {   
            obj.setAttribute("value",obj.getAttribute("oldvalue")); 
        }
        else
        {
            obj.setAttribute("oldvalue",value); 
            settingChange = true;
        }
        unModi(obj,'right');
        obj.parentElement.parentElement.objscore = obj.value;
    }
    //非编辑状态
    function unModi(obj,align)
    {
        if(obj.readOnly == false)
        {
            obj.parentElement.style.textAlign = align;
           obj.style.textAlign = align;  
           obj.style.border = 'solid #ffffff 1px;';   
           obj.readOnly = true; 
           updateActivate = 0;   
        }
    }
    //编辑状态
    function modi(obj)
    { 
        if( obj.readOnly == true)
        {
         //   obj.parentElement.style.textAlign = 'center';
            obj.style.textAlign = 'left';  
            obj.style.border = 'solid #a5a5a5 1px;';   
            obj.readOnly = false;   
            obj.select();
            updateActivate = 1; 
        }
    } 
    var currentObj = null;
    function SetHightLight(obj)
    {
         if(currentObj!=null)
            currentObj.style.backgroundColor = "#ffffff";
         obj.style.backgroundColor = "#fffccf";
         currentObj = obj;
    }
    //被删除的项目
    var delArray = new Array();
    function DelSetting(obj)
    {
        if(obj.id != "null")
        {
            delArray[ delArray.length]=obj.id;
        }
        settingChange = true;
        var settingTable = document.getElementById('settingTable');
        for(i=1;i<settingTable.rows.length;i++)
        {
            if(obj == settingTable.rows[i])
            {
                settingTable.deleteRow(i);
                break;
            }
        }
        
    }
    function OnselectChange(obj,value)
    {
        obj.parentElement.parentElement.objop =value;
        settingChange = true;
    }
    function SaveSettings()
    {
    
        var settingTable = document.getElementById('settingTable');
        if(settingTable==null)
            return;
        var arraytemp = new Array();
        for(i=1;i<settingTable.rows.length;i++)
        {
            arraytemp[i-1] = {"RID":(settingTable.rows[i].id=="null"?-1:settingTable.rows[i].id),
                                "Caption":settingTable.rows[i].objname,
                                "Max":settingTable.rows[i].objmax,
                                "Min":settingTable.rows[i].objmin,
                                "SchoolYear":null,
                                "Term":null,
                                "SchoolMark":null
                                };
        }
        
        PageMethods.SaveUsersSets(arraytemp,delArray,function(result){
            for(i=0;i<result.length;i++)
            {
                settingTable.rows[i+1].id = result[i];
            }
            settingChange = false;
            showMassgeBox("提示","保存完成",1,doThis);
        },function(err){showMassgeBox("提示","err._message",1,doThis);});
    }
    
    //焦点移开后判断更新
    function optionSettingScoremax(obj)
    {
        s=true;
        var id = obj.parentElement.parentElement.id;
        var value = obj.value;

        if(value.length == 0 ||  ( /\D/.test(value)))
        {   
            obj.setAttribute("value",obj.getAttribute("oldvalue")); 
        }
        else
        {
            obj.setAttribute("oldvalue",value); 
            settingChange = true;
        }
        unModi(obj,'right');
        obj.parentElement.parentElement.objmax = obj.value;
    }
        //焦点移开后判断更新
    function optionSettingScoremin(obj)
    {
        s=true;
        var id = obj.parentElement.parentElement.id;
        var value = obj.value;

        if(value.length == 0 ||  ( /\D/.test(value)))
        {   
            obj.setAttribute("value",obj.getAttribute("oldvalue")); 
        }
        else
        {
            obj.setAttribute("oldvalue",value); 
            settingChange = true;
        }
        unModi(obj,'right');
        obj.parentElement.parentElement.objmin = obj.value;
    }
</script>
</head>
<body style="padding-top:5px;">
<form id="form1" runat="server">
<div class="mainWarp">
    <div class="pageBody">
     <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
     </asp:ScriptManager>
        <div style=" height:200px;">
            <input type="button" class="commonBut" id="btnAddKind" value="新增" onclick="AddSetting()" />
            <input type="button" class="commonBut" id="btnSaveKind" value="保存" onclick="SaveSettings()" />
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                        <ContentTemplate>
                <asp:Repeater ID="Repeater1" runat="server">
                    <HeaderTemplate>
                     <div style="overflow-y:auto;overflow-x:none;height:98%;">
                        <table id="settingTable" border="0" cellpadding="0" cellspacing="1" style="width: 50%;"
                            class="useList">
                            <tr>
                                <th width="25%" style="text-align: left; padding-left: 5px;">
                                    等级</th>
                                <th width="25%" style="text-align: right; padding-right: 5px;">
                                    下限
                                </th>
                                <th width="25%" style="text-align: right; padding-right: 5px;">
                                    上限
                                </th>
                                <th width="25%" style="text-align: center;">
                                    删除
                                </th>
                            </tr>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <tr style="background-color: White;" id="<%# Eval("RID")%>" objname="<%# Eval("Caption")%>"
                            objmin="<%# Eval("Min")  %>" objmax="<%# Eval("Max")%>">
                            <td style="text-align: left; padding-left: 5px;">
                                <input  onpaste="return false;" ondragenter="return false"
                                    maxlength="9" class="txtStyle" style='text-align: left; border-left: 0px; width: 120px;
                                    border-top: 0px; border-right: 0px; border-bottom: 0px;' id="n<%# Eval("Caption")%>"
                                    value="<%# Eval("Caption")%>" oldvalue="<%# Eval("Caption")%>" onfocusout="optionSettingName(this)"
                                    onclick="modi(this)" readonly />
                            </td>
                            <td style="text-align: right; padding-right: 5px;">
                                 <input onkeypress="return event.keyCode>=48&&event.keyCode<=57" onpaste="return false;"
                                    ondragenter="return false" maxlength="4" class="txtStyle" style='text-align: right;
                                    border-left: 0px; width: 80px; border-top: 0px; border-right: 0px; border-bottom: 0px;'
                                    id="Text1" value="<%# Eval("Min")%>" oldvalue="<%# Eval("Min")%>"
                                    onfocusout="optionSettingScoremin(this)" onclick="modi(this)" readonly />
                            </td>
                            <td style="text-align: right; padding-right: 5px;">
                                <input onkeypress="return event.keyCode>=48&&event.keyCode<=57" onpaste="return false;"
                                    ondragenter="return false" maxlength="4" class="txtStyle" style='text-align: right;
                                    border-left: 0px; width: 80px; border-top: 0px; border-right: 0px; border-bottom: 0px;'
                                    id="Text2" value="<%# Eval("Max")%>" oldvalue="<%# Eval("Max")%>"
                                    onfocusout="optionSettingScoremax(this)" onclick="modi(this)" readonly />
                            </td>
                            <td style="text-align: center;">
                                <img style='cursor:hand' src="../../../Common/images/delete_icon.gif" alt="删除此项" class="imageBtnStyle" onclick="DelSetting(this.parentElement.parentElement);" />
                            </td>
                        </tr>
                    </ItemTemplate>
                    <FooterTemplate>
                        </table></div>
                    </FooterTemplate>
                </asp:Repeater>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnBind" EventName="Click" />
            </Triggers>
            </asp:UpdatePanel>
        </div>
         <div style="display: none;">
            <asp:Button ID="btnBind" runat="server" OnClick="btnBind_Click" Text="btnBind" />
            <asp:TextBox ID="typeid" runat="server"></asp:TextBox><asp:TextBox ID="examid" runat="server"></asp:TextBox><asp:TextBox ID="classtype" runat="server"></asp:TextBox><asp:TextBox ID="grade" runat="server"></asp:TextBox>
        </div>
    </div>
</div>
    </form>
</body>
</html>
<script language="javascript">
document.getElementById('btnBind').click();;
</script>